package com.hdax.service.Impl;

import com.hdax.entity.Employee;
import com.hdax.mappers.EmployeeMapper;
import com.hdax.service.EmployeeService;
import com.hdax.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 员工服务impl
 *
 * @author Aizen
 * @date 2022/05/03
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    /**
     * 员工映射器
     */
    @Autowired
    private EmployeeMapper employeeMapper;


    /**
     * 发现员工通过员工代码
     * 登录
     *
     * @param empCode emp代码
     * @return {@link Employee}
     */
    @Override
    public Employee findEmployeeByEmployeeCode(String empCode) {
        return employeeMapper.findEmployeeByEmployeeCode(empCode);
    }

    @Override
    public List<Employee> findAll(int offset, int limit,Employee employee) {
        return employeeMapper.findAll(offset,limit,employee);
    }

    @Override
    public Employee selectById(int empId) {
        return employeeMapper.selectById(empId);
    }

    @Override
    public int getByNameCount(String empName) {
        return employeeMapper.getByNameCount(empName);
    }

    @Override
    public ResultUtil deleteById(int empId) {
        try {
            employeeMapper.deleteById(empId);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.upDataResult("删除失败");
        }
        return ResultUtil.upDataResult("删除成功");
    }

    @Override
    public int insertById(Employee employee) {
        return employeeMapper.insertById(employee);
    }

    @Override
    public int updateById(Employee employee) {
        return employeeMapper.updateById(employee);
    }

    /**
     * 添加员工
     * 添加员工(在添加员工档案的时候同步添加员工对应的账号信息
     *
     * @param employee 员工
     */
    @Override
    public void addEmployee(Employee employee) {
        employeeMapper.addEmployee(employee);
    }

    @Override
    public ResultUtil editEmployeeOffByCode(String empCode, String checked) {
        try {
            employeeMapper.editEmployeeOffByCode(empCode,checked);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.upDataResult("修改失败");
        }
        return ResultUtil.upDataResult("修改成功");
    }

    @Override
    public void updateByInfo(Employee employee) {
        employeeMapper.updateByInfo(employee);
    }

}
